<!DOCTYPE html>
<html lang="zh-CN" data-properos-version="1.0">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="description" content="ProperOS - 基于HTML5的轻量级操作系统界面">
    <title>ProperOS</title>
    <style>
        /* 全局样式重置 */
        * {
            -webkit-tap-highlight-color: transparent;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        /* 根变量定义 */
        :root {
            --primary-color: #3F51B5;
            --primary-dark: #303F9F;
            --accent-color: #FF4081;
            --text-color: #333;
            --text-light: #fff;
            --bg-color: #f5f5f5;
            --card-bg: rgba(255, 255, 255, 0.9);
            --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            --border-radius: 12px;
            --transition: all 0.3s ease;
        }
        
        /* 基础页面样式 */
        body {
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            background-size: cover;
            background-attachment: fixed;
            height: 100vh;
            overflow: hidden;
            color: var(--text-color);
            display: flex;
            flex-direction: column;
        }
        
        /* 桌面区域 */
        #desktop {
            flex: 1;
            position: relative;
            overflow: hidden;
            padding: 20px;
        }
        
        /* 欢迎卡片 */
        .welcome-card {
            background: var(--card-bg);
            border-radius: var(--border-radius);
            padding: 30px;
            text-align: center;
            max-width: 500px;
            margin: 100px auto 0;
            box-shadow: var(--shadow);
            backdrop-filter: blur(10px);
        }
        
        .welcome-card h1 {
            color: var(--primary-dark);
            margin-bottom: 15px;
            font-size: 2.2rem;
        }
        
        .welcome-card p {
            margin-bottom: 20px;
            line-height: 1.6;
            color: #555;
        }
        
        /* 统计信息 */
        .stats {
            display: flex;
            justify-content: center;
            gap: 30px;
            margin: 25px 0;
        }
        
        .stat-item {
            display: flex;
            flex-direction: column;
        }
        
        .stat-value {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--primary-color);
        }
        
        .stat-label {
            font-size: 0.9rem;
            color: #777;
        }
        
        /* 系统信息 */
        .system-info {
            background: rgba(255, 255, 255, 0.2);
            border-radius: var(--border-radius);
            padding: 15px;
            margin-top: 20px;
            text-align: left;
            font-size: 14px;
        }
        
        .system-info div {
            margin: 5px 0;
        }
        
        /* 应用网格 */
        .app-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
            gap: 25px;
            max-width: 600px;
            margin: 0 auto;
        }
        
        /* 应用图标 */
        .app-icon {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: var(--transition);
            border-radius: var(--border-radius);
            padding: 10px;
            text-align: center;
        }
        
        .app-icon:hover {
            transform: translateY(-5px);
            background: rgba(255, 255, 255, 0.2);
        }
        
        .app-icon img {
            width: 50px;
            height: 50px;
            object-fit: contain;
            margin-bottom: 8px;
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.8);
            padding: 8px;
            box-shadow: var(--shadow);
        }
        
        .app-icon span {
            color: var(--text-light);
            font-size: 12px;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
            font-weight: 500;
        }
        
        /* 底部Dock栏 */
        #dock {
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            display: flex;
            background: rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(10px);
            border-radius: 24px;
            padding: 8px 16px;
            box-shadow: var(--shadow);
            z-index: 1000;
        }
        
        .dock-icon {
            width: 50px;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 8px;
            cursor: pointer;
            transition: var(--transition);
            border-radius: 12px;
        }
        
        .dock-icon img {
            width: 40px;
            height: 40px;
            object-fit: contain;
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.8);
            padding: 6px;
            box-shadow: var(--shadow);
        }
        
        .dock-icon:hover {
            transform: translateY(-8px) scale(1.1);
        }
        
        /* 顶部状态栏 */
        #status-bar {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 30px;
            background: rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 20px;
            color: var(--text-light);
            font-size: 14px;
            font-weight: 500;
            z-index: 1000;
        }
        
        .system-icons {
            display: flex;
            gap: 15px;
        }
        
        /* 应用窗口 */
        .app-window {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 85%;
            max-width: 800px;
            height: 70%;
            background: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            overflow: hidden;
            display: none;
            z-index: 100;
            flex-direction: column;
        }
        
        .app-window.active {
            display: flex;
            animation: window-open 0.4s ease forwards;
        }
        
        @keyframes window-open {
            from { opacity: 0; transform: translate(-50%, -40%); }
            to { opacity: 1; transform: translate(-50%, -50%); }
        }
        
        .title-bar {
            background: var(--primary-color);
            color: var(--text-light);
            padding: 10px 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: 500;
        }
        
        .window-controls {
            display: flex;
            gap: 10px;
        }
        
        .window-btn {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            background: rgba(255, 255, 255, 0.2);
            transition: var(--transition);
        }
        
        .window-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }
        
        .app-content {
            flex: 1;
            padding: 20px;
            overflow: auto;
        }
        
        /* 应用管理器特定样式 */
        .app-manager {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 12px;
            padding: 20px;
            margin: 20px auto;
            max-width: 800px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        .app-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 15px;
            margin-top: 20px;
        }
        
        .app-card {
            background: white;
            border-radius: 8px;
            padding: 15px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .app-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
        }
        
        .app-icon-large {
            width: 60px;
            height: 60px;
            margin: 0 auto 10px;
            display: block;
        }
        
        .app-actions {
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
        }
        
        .btn {
            padding: 6px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s ease;
        }
        
        .btn-primary {
            background: #3F51B5;
            color: white;
        }
        
        .btn-danger {
            background: #F44336;
            color: white;
        }
        
        .btn:hover {
            opacity: 0.9;
        }
        
        .install-form {
            margin-top: 20px;
            padding: 15px;
            background: #f5f5f5;
            border-radius: 8px;
        }
        
        .form-group {
            margin-bottom: 15px;
        }
        
        .form-control {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .app-grid {
                grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
                gap: 15px;
            }
            
            .app-icon img {
                width: 45px;
                height: 45px;
            }
            
            .welcome-card {
                margin-top: 70px;
                padding: 20px;
            }
            
            .app-list {
                grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
            }
        }
        
        @media (max-width: 480px) {
            .app-list {
                grid-template-columns: 1fr;
            }
            
            #dock {
                padding: 6px 12px;
            }
            
            .dock-icon {
                width: 42px;
                height: 42px;
                margin: 0 5px;
            }
            
            .dock-icon img {
                width: 36px;
                height: 36px;
            }
        }
    </style>
</head>
<body>
    <!-- 桌面区域 -->
    <div id="desktop">
        <!-- 欢迎卡片 -->
        <div class="welcome-card">
            <h1>ProperOS</h1>
            <p>基于HTML5的轻量级操作系统界面</p>
            
            <div class="stats">
                <div class="stat-item">
                    <div class="stat-value" id="app-count">8</div>
                    <div class="stat-label">应用</div>
                </div>
                <div class="stat-item">
                    <div class="stat-value" id="user-online">1</div>
                    <div class="stat-label">在线</div>
                </div>
                <div class="stat-item">
                    <div class="stat-value">0.1.0</div>
                    <div class="stat-label">版本</div>
                </div>
            </div>
            
            <div class="system-info">
                <div>设备: <span id="device-info">正在加载...</span></div>
                <div>平台: <span id="platform-info">HTML5/JavaScript</span></div>
                <div>状态: <span id="system-status">运行中</span></div>
            </div>
        </div>
        
        <!-- 应用网格 -->
        <div class="app-grid" id="app-grid">
            <!-- 应用图标将通过JS动态添加 -->
        </div>
    </div>
    
    <!-- 底部Dock栏 -->
    <div id="dock">
        <div class="dock-icon" data-app="explorer">
            <img src="https://cdn-icons-png.flaticon.com/512/716/716784.png" alt="文件管理器">
        </div>
        <div class="dock-icon" data-app="browser">
            <img src="https://cdn-icons-png.flaticon.com/512/1006/1006771.png" alt="浏览器">
        </div>
        <div class="dock-icon" data-app="settings">
            <img src="https://cdn-icons-png.flaticon.com/512/126/126472.png" alt="设置">
        </div>
        <div class="dock-icon" data-app="terminal">
            <img src="https://cdn-icons-png.flaticon.com/512/61/61140.png" alt="终端">
        </div>
    </div>
    
    <!-- 顶部状态栏 -->
    <div id="status-bar">
        <div class="time" id="clock">00:00</div>
        <div class="system-icons">
            <span>WiFi</span>
            <span>电池: 100%</span>
            <span id="date-display">2023年10月15日</span>
        </div>
    </div>
    
    <!-- 应用窗口容器 -->
    <div id="app-windows">
        <!-- 应用管理器窗口 -->
        <div class="app-window" id="app-manager-window">
            <div class="title-bar">
                <div class="title">应用管理器</div>
                <div class="window-controls">
                    <div class="window-btn minimize">−</div>
                    <div class="window-btn maximize">□</div>
                    <div class="window-btn close">×</div>
                </div>
            </div>
            <div class="app-content">
                <div class="app-manager">
                    <h2>已安装应用</h2>
                    <div class="app-list" id="installed-apps">
                        <!-- 应用列表将通过JS动态加载 -->
                    </div>
                    
                    <h2>安装新应用</h2>
                    <div class="install-form">
                        <div class="form-group">
                            <label>应用ID:</label>
                            <input type="text" class="form-control" id="app-id" placeholder="如: com.example.myapp">
                        </div>
                        <div class="form-group">
                            <label>应用名称:</label>
                            <input type="text" class="form-control" id="app-name" placeholder="应用显示名称">
                        </div>
                        <div class="form-group">
                            <label>版本:</label>
                            <input type="text" class="form-control" id="app-version" value="1.0.0" placeholder="版本号">
                        </div>
                        <div class="form-group">
                            <label>图标URL:</label>
                            <input type="text" class="form-control" id="app-icon" 
                                   value="https://cdn-icons-png.flaticon.com/512/2965/2965300.png" 
                                   placeholder="图标URL地址">
                        </div>
                        <div class="form-group">
                            <label>描述:</label>
                            <textarea class="form-control" id="app-description" rows="3" placeholder="应用描述"></textarea>
                        </div>
                        <button class="btn btn-primary" id="install-btn">安装应用</button>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 设置窗口 -->
        <div class="app-window" id="settings-window">
            <div class="title-bar">
                <div class="title">系统设置</div>
                <div class="window-controls">
                    <div class="window-btn close">×</div>
                </div>
            </div>
            <div class="app-content">
                <h2>系统设置</h2>
                <div class="settings-section">
                    <h3>外观</h3>
                    <div class="setting-item">
                        <label>主题:</label>
                        <select id="theme-selector" class="form-control">
                            <option value="light">浅色</option>
                            <option value="dark">深色</option>
                            <option value="auto">自动</option>
                        </select>
                    </div>
                    <div class="setting-item">
                        <label>壁纸:</label>
                        <select id="wallpaper-selector" class="form-control">
                            <option value="default">默认</option>
                            <option value="nature">自然</option>
                            <option value="abstract">抽象</option>
                            <option value="solid">纯色</option>
                        </select>
                    </div>
                </div>
                
                <div class="settings-section">
                    <h3>系统</h3>
                    <div class="setting-item">
                        <label>语言:</label>
                        <select id="language-selector" class="form-control">
                            <option value="zh-CN">简体中文</option>
                            <option value="en-US">English</option>
                        </select>
                    </div>
                </div>
                
                <div class="settings-actions">
                    <button class="btn btn-primary" id="save-settings">保存设置</button>
                    <button class="btn" id="reset-settings">恢复默认</button>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // ProperOS 主类
        class ProperOS {
            constructor() {
                this.version = "1.0";
                this.apps = [];
                this.settings = {};
                this.windows = {};
                this.init();
            }
            
            init() {
                // 加载系统设置
                this.loadSettings();
                
                // 初始化UI
                this.initUI();
                
                // 加载已安装应用
                this.loadApps();
                
                // 启动系统服务
                this.startServices();
                
                // 初始化窗口事件
                this.initWindowEvents();
            }
            
            loadSettings() {
                // 从本地存储加载或使用默认设置
                this.settings = JSON.parse(localStorage.getItem('properos_settings')) || {
                    theme: 'light',
                    wallpaper: 'default',
                    language: 'zh-CN'
                };
                
                // 应用设置
                this.applySettings();
            }
            
            saveSettings() {
                localStorage.setItem('properos_settings', JSON.stringify(this.settings));
                this.applySettings();
            }
            
            applySettings() {
                // 应用主题设置
                document.documentElement.setAttribute('data-theme', this.settings.theme);
                
                // 应用壁纸设置
                this.setWallpaper(this.settings.wallpaper);
            }
            
            setWallpaper(wallpaper) {
                let wallpaperUrl = '';
                switch(wallpaper) {
                    case 'nature':
                        wallpaperUrl = 'url(https://source.unsplash.com/random/1920x1080/?nature)';
                        break;
                    case 'abstract':
                        wallpaperUrl = 'url(https://source.unsplash.com/random/1920x1080/?abstract)';
                        break;
                    case 'solid':
                        wallpaperUrl = 'linear-gradient(135deg, #6a11cb 0%, #2575fc 100%)';
                        break;
                    default:
                        wallpaperUrl = 'linear-gradient(135deg, #6a11cb 0%, #2575fc 100%)';
                }
                
                document.body.style.background = wallpaperUrl;
                document.body.style.backgroundSize = 'cover';
                document.body.style.backgroundAttachment = 'fixed';
            }
            
            initUI() {
                // 更新时钟
                this.updateClock();
                setInterval(() => this.updateClock(), 60000);
                
                // 更新日期
                this.updateDate();
                
                // 加载设备信息
                this.loadDeviceInfo();
                
                // 初始化设置表单
                this.initSettingsForm();
            }
            
            updateClock() {
                const now = new Date();
                const hours = now.getHours().toString().padStart(2, '0');
                const minutes = now.getMinutes().toString().padStart(2, '0');
                document.getElementById('clock').textContent = `${hours}:${minutes}`;
            }
            
            updateDate() {
                const now = new Date();
                const year = now.getFullYear();
                const month = now.getMonth() + 1;
                const day = now.getDate();
                document.getElementById('date-display').textContent = `${year}年${month}月${day}日`;
            }
            
            loadDeviceInfo() {
                if (typeof ProperOSAndroid !== 'undefined') {
                    const info = ProperOSAndroid.getSystemInfo();
                    document.getElementById('device-info').textContent = info;
                } else {
                    document.getElementById('device-info').textContent = "模拟环境";
                }
            }
            
            initSettingsForm() {
                // 设置当前值
                document.getElementById('theme-selector').value = this.settings.theme;
                document.getElementById('wallpaper-selector').value = this.settings.wallpaper;
                document.getElementById('language-selector').value = this.settings.language;
                
                // 添加事件监听
                document.getElementById('save-settings').addEventListener('click', () => {
                    this.settings.theme = document.getElementById('theme-selector').value;
                    this.settings.wallpaper = document.getElementById('wallpaper-selector').value;
                    this.settings.language = document.getElementById('language-selector').value;
                    this.saveSettings();
                    alert('设置已保存');
                });
                
                document.getElementById('reset-settings').addEventListener('click', () => {
                    if (confirm('确定要恢复默认设置吗？')) {
                        this.settings = {
                            theme: 'light',
                            wallpaper: 'default',
                            language: 'zh-CN'
                        };
                        this.saveSettings();
                        location.reload();
                    }
                });
            }
            
            initWindowEvents() {
                // 应用管理器窗口事件
                const appManagerWindow = document.getElementById('app-manager-window');
                appManagerWindow.querySelector('.close').addEventListener('click', () => {
                    appManagerWindow.style.display = 'none';
                });
                
                appManagerWindow.querySelector('.minimize').addEventListener('click', () => {
                    // 最小化逻辑
                });
                
                appManagerWindow.querySelector('.maximize').addEventListener('click', () => {
                    // 最大化逻辑
                });
                
                // 设置窗口事件
                const settingsWindow = document.getElementById('settings-window');
                settingsWindow.querySelector('.close').addEventListener('click', () => {
                    settingsWindow.style.display = 'none';
                });
                
                // 安装按钮事件
                document.getElementById('install-btn').addEventListener('click', () => {
                    this.installApp();
                });
            }
            
            loadApps() {
                // 系统内置应用
                this.systemApps = [
                    {
                        id: "explorer",
                        name: "文件管理器",
                        icon: "https://cdn-icons-png.flaticon.com/512/716/716784.png",
                        url: "explorer.html",
                        version: "1.0.0",
                        description: "管理系统文件和文件夹"
                    },
                    {
                        id: "browser",
                        name: "浏览器",
                        icon: "https://cdn-icons-png.flaticon.com/512/1006/1006771.png",
                        url: "browser.html",
                        version: "2.1.3",
                        description: "网页浏览工具"
                    },
                    {
                        id: "settings",
                        name: "系统设置",
                        icon: "https://cdn-icons-png.flaticon.com/512/126/126472.png",
                        url: "settings.html",
                        version: "1.0.0",
                        description: "系统配置和设置"
                    },
                    {
                        id: "terminal",
                        name: "终端",
                        icon: "https://cdn-icons-png.flaticon.com/512/61/61140.png",
                        url: "terminal.html",
                        version: "1.2.1",
                        description: "命令行终端"
                    },
                    {
                        id: "calculator",
                        name: "计算器",
                        icon: "https://cdn-icons-png.flaticon.com/512/1250/1250710.png",
                        url: "calculator.html",
                        version: "1.0.1",
                        description: "科学计算器"
                    },
                    {
                        id: "calendar",
                        name: "日历",
                        icon: "https://cdn-icons-png.flaticon.com/512/3652/3652191.png",
                        url: "calendar.html",
                        version: "1.3.0",
                        description: "日历和日程管理"
                    },
                    {
                        id: "camera",
                        name: "相机",
                        icon: "https://cdn-icons-png.flaticon.com/512/1150/1150635.png",
                        url: "camera.html",
                        version: "2.0.0",
                        description: "拍照和录像"
                    },
                    {
                        id: "app-store",
                        name: "应用商店",
                        icon: "https://cdn-icons-png.flaticon.com/512/869/869869.png",
                        url: "app-store.html",
                        version: "1.5.2",
                        description: "下载和安装新应用"
                    }
                ];
                
                // 合并系统应用和安装的应用
                this.apps = [...this.systemApps];
                
                // 加载用户安装的应用
                this.loadInstalledApps();
                
                // 更新应用计数
                document.getElementById('app-count').textContent = this.apps.length;
                
                // 渲染应用图标
                this.renderAppIcons();
                
                // 设置Dock栏事件
                this.setupDockEvents();
            }
            
            loadInstalledApps() {
                if (typeof ProperOSAndroid !== 'undefined') {
                    try {
                        const installedAppsJson = ProperOSAndroid.getInstalledApps();
                        if (installedAppsJson) {
                            const installedApps = JSON.parse(installedAppsJson);
                            this.apps = [...this.systemApps, ...installedApps];
                        }
                    } catch (e) {
                        console.error('Error loading installed apps:', e);
                    }
                }
            }
            
            renderAppIcons() {
                const appGrid = document.getElementById('app-grid');
                appGrid.innerHTML = '';
                
                this.apps.forEach(app => {
                    const appElement = document.createElement('div');
                    appElement.className = 'app-icon';
                    appElement.dataset.app = app.id;
                    appElement.innerHTML = `
                        <img src="${app.icon}" alt="${app.name}">
                        <span>${app.name}</span>
                    `;
                    appElement.addEventListener('click', () => this.launchApp(app));
                    appGrid.appendChild(appElement);
                });
            }
            
            setupDockEvents() {
                const dockIcons = document.querySelectorAll('.dock-icon');
                dockIcons.forEach(icon => {
                    const appId = icon.dataset.app;
                    const app = this.apps.find(a => a.id === appId);
                    if (app) {
                        icon.addEventListener('click', () => this.launchApp(app));
                    }
                });
                
                // 添加应用管理器按钮到Dock
                const appManagerBtn = document.createElement('div');
                appManagerBtn.className = 'dock-icon';
                appManagerBtn.innerHTML = '<img src="https://cdn-icons-png.flaticon.com/512/2889/2889676.png" alt="应用管理器">';
                appManagerBtn.addEventListener('click', () => this.showAppManager());
                document.getElementById('dock').appendChild(appManagerBtn);
            }
            
            showAppManager() {
                const appManagerWindow = document.getElementById('app-manager-window');
                appManagerWindow.style.display = 'flex';
                appManagerWindow.style.top = '50%';
                appManagerWindow.style.left = '50%';
                appManagerWindow.style.transform = 'translate(-50%, -50%)';
                
                this.loadAppManagerContent();
            }
            
            loadAppManagerContent() {
                const installedAppsList = document.getElementById('installed-apps');
                installedAppsList.innerHTML = '';
                
                this.apps.forEach(app => {
                    const appCard = document.createElement('div');
                    appCard.className = 'app-card';
                    appCard.innerHTML = `
                        <img src="${app.icon}" class="app-icon-large" alt="${app.name}">
                        <h3>${app.name}</h3>
                        <p>版本: ${app.version || '1.0.0'}</p>
                        <p>${app.description || '没有描述信息'}</p>
                        <div class="app-actions">
                            <button class="btn btn-primary" data-app-id="${app.id}">启动</button>
                            ${app.id.startsWith('com.') ? `<button class="btn btn-danger" data-app-id="${app.id}">卸载</button>` : ''}
                        </div>
                    `;
                    
                    installedAppsList.appendChild(appCard);
                    
                    // 添加事件监听
                    appCard.querySelector('.btn-primary').addEventListener('click', () => {
                        this.launchApp(app);
                    });
                    
                    const uninstallBtn = appCard.querySelector('.btn-danger');
                    if (uninstallBtn) {
                        uninstallBtn.addEventListener('click', () => {
                            this.uninstallApp(app.id);
                        });
                    }
                });
            }
            
            installApp() {
                const appId = document.getElementById('app-id').value.trim();
                const appName = document.getElementById('app-name').value.trim();
                const appVersion = document.getElementById('app-version').value.trim();
                const appIcon = document.getElementById('app-icon').value.trim();
                const appDescription = document.getElementById('app-description').value.trim();
                
                if (!appId || !appName) {
                    alert('请填写应用ID和名称');
                    return;
                }
                
                // 验证应用ID格式
                if (!/^[a-z][a-z0-9_]*(?:\.[a-z0-9_]+)+$/.test(appId)) {
                    alert('应用ID格式不正确，应类似: com.example.myapp');
                    return;
                }
                
                const appData = {
                    id: appId,
                    name: appName,
                    version: appVersion || "1.0.0",
                    icon: appIcon || "https://cdn-icons-png.flaticon.com/512/2965/2965300.png",
                    url: `app://${appId}`,
                    description: appDescription || "新安装的应用"
                };
                
                if (typeof ProperOSAndroid !== 'undefined') {
                    const success = ProperOSAndroid.installApp(JSON.stringify(appData));
                    if (success) {
                        alert('应用安装成功');
                        this.loadApps();
                        this.loadAppManagerContent();
                        
                        // 清空表单
                        document.getElementById('app-id').value = '';
                        document.getElementById('app-name').value = '';
                        document.getElementById('app-description').value = '';
                    } else {
                        alert('应用安装失败');
                    }
                } else {
                    // 模拟安装
                    console.log('模拟安装应用:', appData);
                    alert('模拟: 应用安装成功');
                    this.apps.push(appData);
                    this.loadAppManagerContent();
                }
            }
            
            uninstallApp(appId) {
                if (confirm(`确定要卸载应用 ${appId} 吗？`)) {
                    if (typeof ProperOSAndroid !== 'undefined') {
                        const success = ProperOSAndroid.uninstallApp(appId);
                        if (success) {
                            alert('应用卸载成功');
                            this.loadApps();
                            this.loadAppManagerContent();
                        } else {
                            alert('应用卸载失败');
                        }
                    } else {
                        // 模拟卸载
                        console.log('模拟卸载应用:', appId);
                        alert('模拟: 应用卸载成功');
                        this.apps = this.apps.filter(app => app.id !== appId);
                        this.loadAppManagerContent();
                    }
                }
            }
            
            launchApp(app) {
                // 特殊应用处理
                if (app.id === 'settings') {
                    this.showSettings();
                    return;
                }
                
                if (app.id === 'app-manager') {
                    this.showAppManager();
                    return;
                }
                
                // 在实际实现中，这里会加载应用内容
                this.openAppWindow(app);
            }
            
            showSettings() {
                const settingsWindow = document.getElementById('settings-window');
                settingsWindow.style.display = 'flex';
                settingsWindow.style.top = '50%';
                settingsWindow.style.left = '50%';
                settingsWindow.style.transform = 'translate(-50%, -50%)';
            }
            
            openAppWindow(app) {
                const windowId = `app-${app.id}`;
                let window = document.getElementById(windowId);
                
                if (!window) {
                    window = document.createElement('div');
                    window.id = windowId;
                    window.className = 'app-window';
                    window.innerHTML = `
                        <div class="title-bar">
                            <div class="title">${app.name}</div>
                            <div class="window-controls">
                                <div class="window-btn minimize">−</div>
                                <div class="window-btn maximize">□</div>
                                <div class="window-btn close">×</div>
                            </div>
                        </div>
                        <div class="app-content">
                            <h2>${app.name}</h2>
                            <p>版本: ${app.version || '1.0.0'}</p>
                            <p>ID: ${app.id}</p>
                            <div style="margin-top: 20px; padding: 20px; background: #f0f0f0; border-radius: 8px;">
                                <p>${app.description || '这是应用的功能界面'}</p>
                                <p>在实际实现中，这里会加载应用的具体功能</p>
                                <button class="btn btn-primary close-btn" style="margin-top:15px;">关闭</button>
                            </div>
                        </div>
                    `;
                    
                    document.getElementById('app-windows').appendChild(window);
                    
                    // 添加窗口控制功能
                    window.querySelector('.close').addEventListener('click', () => {
                        window.remove();
                    });
                    
                    window.querySelector('.minimize').addEventListener('click', () => {
                        window.style.display = 'none';
                    });
                    
                    window.querySelector('.maximize').addEventListener('click', () => {
                        if (window.style.width === '100%') {
                            window.style.width = '85%';
                            window.style.height = '70%';
                        } else {
                            window.style.width = '100%';
                            window.style.height = '100%';
                        }
                    });
                    
                    const closeBtn = window.querySelector('.close-btn');
                    if (closeBtn) {
                        closeBtn.addEventListener('click', () => {
                            window.remove();
                        });
                    }
                }
                
                window.style.display = 'flex';
                window.style.top = '50%';
                window.style.left = '50%';
                window.style.transform = 'translate(-50%, -50%)';
                
                // 将窗口带到最前面
                document.querySelectorAll('.app-window').forEach(w => {
                    w.style.zIndex = '100';
                });
                window.style.zIndex = '200';
            }
            
            startServices() {
                // 模拟后台服务
                console.log('ProperOS 服务已启动');
                
                // 模拟用户在线状态
                setInterval(() => {
                    document.getElementById('user-online').textContent = "1";
                }, 5000);
            }
        }
        
        // 初始化ProperOS
        document.addEventListener('DOMContentLoaded', () => {
            window.ProperOS = new ProperOS();
        });
    </script>
</body>
</html>